import { applyMiddleware, createStore } from 'redux'
import axios from 'axios'
// import logger from 'redux-logger'
import thunk from 'redux-thunk'


// reducer  函数
// initState  初始数据
// 添加中间件

// 纯函数(没有副作用)
let reducer = (state, action) => {
    // console.log('我执行到了reducer', action)
    let NewState = JSON.parse(JSON.stringify(state))
    switch(action.type) {
        case 'ADD':
            NewState.count += 1
            return NewState
        case 'DEL':
            NewState.count -= 1
            return NewState
        case 'GET_LIST':
            // axios.get('/getList').then(res => {
            //     NewState.list = res.data.list
            // })
            NewState.list = action.list
            return NewState
        default:
            return state
    }
}

let initState = {
    count: 888,
    title: "我是标题",
    list: []
}

let store = createStore(reducer, initState, applyMiddleware(thunk))
window.store = store

export default store
